//
//  Numeric+Extension.swift
//  TA
//
//  Created by M on 2019/12/11.
//  Copyright © 2019 m. All rights reserved.
//

import UIKit

public extension CGFloat {

    /// 时间转换 秒 -> 分:秒
    var transferTime: String {
        var min: Int = 0
        var sec: Int = Int(self)
        if sec >= 60 {
            let index = sec / 60
            min = index
            sec = sec - index * 60
        }
        return "\(min):\(sec < 10 ? "0\(sec)" : "\(sec)")"
    }
    
}

public extension Double {
    
    /// 时间转换 秒 -> 分:秒
    var transferTime: String {
        var min: Int = 0
        var sec: Int = Int(self)
        if sec >= 60 {
            let index = sec / 60
            min = index
            sec = sec - index * 60
        }
        return "\(min):\(sec < 10 ? "0\(sec)" : "\(sec)")"
    }
    
    /**
     保留X位小数
     
     @param         places: 位数
     */
    func roundedTo(places: Int) -> Double {
        let divisor = pow(10.0, Double(places))
        return (self * divisor).rounded() / divisor
    }
    
}
